package cn.legend.travel.admin.destination.controller;

import cn.legend.travel.admin.destination.pojo.param.DelicacyAddNewParam;
import cn.legend.travel.admin.destination.pojo.param.DelicacyUpdateParam;
import cn.legend.travel.admin.destination.service.IDelicacyService;
import cn.legend.travel.common.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "美食管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("delicacies")
public class DelicacyController {
    private final IDelicacyService service;

    @GetMapping("list")
    @ApiOperation("获取美食列表")
    @PreAuthorize("hasAuthority('/delicacies/manage')")
    public JsonResult list(Integer pageNum) {
        return JsonResult.ok(service.list(pageNum == null ? 1 : pageNum));
    }

    @PostMapping("update")
    @ApiOperation("更改美食")
    @PreAuthorize("hasAuthority('/delicacies/manage')")
    public JsonResult update(@RequestBody DelicacyUpdateParam param) {
        service.update(param);
        return JsonResult.ok();
    }

    @PostMapping("delete")
    @ApiOperation("删除美食")
    @PreAuthorize("hasAuthority('/delicacies/manage')")
    public JsonResult delete(@RequestParam Long id) {
        service.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("addNew")
    @ApiOperation("添加美食")
    @PreAuthorize("hasAuthority('/delicacies/addNew')")
    public JsonResult addNew(@RequestBody DelicacyAddNewParam param) {
        service.addNew(param);
        return JsonResult.ok();
    }
}
